#include <pubbase.h>

void tool_gettime( char * opczTime )
{
   time_t        lCurrTime;
   struct tm   *pstTM;

   time( &lCurrTime );

   pstTM = localtime( &lCurrTime );

   pstTM->tm_year += 1900;
   pstTM->tm_mon += 1;
   sprintf(opczTime, "%02d%02d%02d%02d%02d", 
           pstTM->tm_mon, pstTM->tm_mday, pstTM->tm_hour,
           pstTM->tm_min, pstTM->tm_sec);
}

int TOOL_Log(char * log_name, char * file_name, int line, char *format, ...)
{
    va_list args;
    time_t itime;
    FILE *fp = NULL;
    char aczFormat[256] = {0};
    char aczMsg[512] = {0};
    char czTime[20] = {0};

    tool_gettime(czTime);
    fp = fopen(log_name, "a");
    va_start(args, format);
    sprintf(aczFormat, "%s|%d|%s|%s\n", file_name, line, czTime, format);
    vsnprintf(aczMsg, sizeof(aczMsg), aczFormat, args);
    va_end(args);
    fputs(aczMsg, fp);
    fclose(fp);
    return 0;
}
